﻿using Abp.Application.Services.Dto;
using Abp.AspNetCore.Mvc.Controllers;
using Abp.Runtime.Validation;
using Batman.Cms.Controllers.Weixins.Input;
using Batman.Cms.Services.Weixins;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace Batman.Cms.Controllers.Weixins
{
    public class WeixinQrCodeController : AbpController
    {
        public ActionResult Create()
        {
            return View(new CreateQrCodeInput());
        }

        public WeixinQrCodeAppSvc WeixinQrCodeAppSvc { get; set; }

        [DisableValidation]
        [HttpPost]
        public async Task<ActionResult> Create(CreateQrCodeInput model)
        {
            if (!ModelState.IsValid) return View(model);
            var result = await WeixinQrCodeAppSvc.Create(model);

            if (!result.Success)
            {
                result.AddModelError(ModelState);
                return View(model);
            }
            return Content("创建带参二维码成功");
        }

        public ActionResult Index(PagedResultRequestDto page)
        {
            var model = WeixinQrCodeAppSvc.GetQrCodes(page);

            return View(model);
        }
    }
}
